﻿<UserControl x:Class="FSquirrel.Views.CategoryTreeView"
        xmlns="http://schemas.microsoft.com/winfx/2006/xaml/presentation"
        xmlns:x="http://schemas.microsoft.com/winfx/2006/xaml"
        xmlns:d="http://schemas.microsoft.com/expression/blend/2008"
        xmlns:mc="http://schemas.openxmlformats.org/markup-compatibility/2006"
        xmlns:ignore="http://www.ignore.com" 
        xmlns:scm="clr-namespace:System.ComponentModel;assembly=WindowsBase"
        xmlns:i="clr-namespace:System.Windows.Interactivity;assembly=System.Windows.Interactivity"
xmlns:cmd="clr-namespace:GalaSoft.MvvmLight.Command;assembly=GalaSoft.MvvmLight.Extras.WPF45"
             xmlns:helper="clr-namespace:FSquirrel.Helpers" mc:Ignorable="d ignore">
    <!--DataContext="{Binding ViewModelName, Source={StaticResource Locator}}">-->
    <UserControl.Resources>

        <CollectionViewSource x:Key="cvs" Source="{Binding Source={StaticResource Locator},Path=Main.FilterShowListCollection}">
            <CollectionViewSource.GroupDescriptions>
                <PropertyGroupDescription PropertyName="LibraryName"/>
                <PropertyGroupDescription PropertyName="Category"/>
                <PropertyGroupDescription PropertyName="ShowName" StringComparison="InvariantCultureIgnoreCase"/>
                <PropertyGroupDescription PropertyName="ShowSeason"/>

            </CollectionViewSource.GroupDescriptions>
            <CollectionViewSource.SortDescriptions>
                <scm:SortDescription PropertyName="Category" />
                <scm:SortDescription PropertyName="ShowName"/>
                <scm:SortDescription PropertyName="ShowSeason" />
            </CollectionViewSource.SortDescriptions>
        </CollectionViewSource>

        <HierarchicalDataTemplate x:Key="categoryTemplate" ItemsSource="{Binding Path=Items}">
            <TextBlock Text="{Binding Path=Name}" FontWeight="Bold"/>
            <HierarchicalDataTemplate.ItemTemplate>
                <DataTemplate>
                    <TextBlock Text="{Binding Path=Name}">
                
                    </TextBlock>
                </DataTemplate>
            </HierarchicalDataTemplate.ItemTemplate>
        </HierarchicalDataTemplate>

        <helper:DepthSelector x:Key="DepthTemplateSelector"
                              BottomLevel="{StaticResource categoryTemplate}"/>

        <HierarchicalDataTemplate x:Key="ShowTemplate" ItemsSource="{Binding Path=Items}" ItemTemplateSelector="{StaticResource DepthTemplateSelector}">
            
            <!--ItemTemplate="{StaticResource categoryTemplate}"-->
            <TextBlock Text="{Binding Path=Name}" FontWeight="Bold" >
              
            </TextBlock>
        </HierarchicalDataTemplate>
        <HierarchicalDataTemplate x:Key="SeasonTemplate" ItemsSource="{Binding Path=Items}" ItemTemplate="{StaticResource ShowTemplate}" >
            <HierarchicalDataTemplate.ItemContainerStyle>
                <Style TargetType="{x:Type TreeViewItem}">
                    <EventSetter Event="TreeViewItem.PreviewMouseRightButtonDown" Handler="treeview1_MouseRightButtonUp"/>
                    <Setter Property="ContextMenu">
                        <Setter.Value>
                            <ContextMenu>
                                <MenuItem Header="Add to Request" Command="{Binding Source={StaticResource Locator}, Path=Main.TreeRequestCommand}" />
                            </ContextMenu>
                        </Setter.Value>
                    </Setter>
                </Style>
            </HierarchicalDataTemplate.ItemContainerStyle>
            <TextBlock Text="{Binding Path=Name}" FontWeight="Bold" >
             
            </TextBlock>
        </HierarchicalDataTemplate>

    </UserControl.Resources>
    <TreeView ItemsSource="{Binding Source={StaticResource cvs}, Path=Groups}" Width="200" ItemTemplate="{StaticResource SeasonTemplate}"  x:Name="treeview1" >
        <!--ItemTemplateSelector ="{StaticResource DepthTemplateSelector}"-->
        <i:Interaction.Triggers>
            <i:EventTrigger EventName="SelectedItemChanged">
                <cmd:EventToCommand Command="{Binding Source={StaticResource Locator}, Path=Main.SelectedTreeviewCommand}" CommandParameter="{Binding ElementName=treeview1,Path=SelectedValue}" />
            </i:EventTrigger>
        </i:Interaction.Triggers>
    </TreeView>

</UserControl>